package com.niit.schoolhub.system.controller;


import com.niit.schoolhub.system.dto.ApiJson;
import com.niit.schoolhub.system.mapper.YesapiBjyOauthUserMapper;
import com.niit.schoolhub.system.pojo.YesapiBjyOauthUser;
import com.niit.schoolhub.system.utils.JwtFormat;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 博客-第三方登录表 前端控制器
 * </p>
 *
 * @author kaguya
 * @since 2021-11-27
 */
@RestController
@CrossOrigin
@RequestMapping("/system/yesapiBjyOauthUser")
public class YesapiBjyOauthUserController {

    @Autowired
    private YesapiBjyOauthUserMapper yesapiBjyOauthUserMapper;

    @GetMapping("/checktoken")
    public Boolean checkToken(HttpServletRequest request){
        String token = request.getHeader("token");
        if (token==null){
            System.out.println("666");
            return false;
        }
            try {
                Claims claims = JwtFormat.verifyJwt(token);
            }
            catch (Exception e){
                System.out.println("888");
                return false;
            }
        return true;
    }

    @PostMapping("/update/user")
    public ApiJson updateUser(@RequestBody YesapiBjyOauthUser yesapiBjyOauthUser){
        int i = yesapiBjyOauthUserMapper.updateById(yesapiBjyOauthUser);
        if (i>0){
            return ApiJson.ok("更新成功");
        }
        else{
            return  ApiJson.error("更新失败");
        }
    }
}

